<?php
class CourseStudentAction extends CommonAction {

	public function courseList() {
		$map =  array ();
		$pagenum = isset ( $_POST ['page'] ) ? intval ( $_POST ['page'] ) : 1;
		$rowsnum = isset ( $_POST ['rows'] ) ? intval ( $_POST ['rows'] ) : 10;
		
		if( !empty($_POST ['XQ'])){
			$map['KC_XQ'] = $_POST ['XQ'];
		}
		if( !empty($_POST ['NJ'])){
			$map['KC_NJ'] = $_POST ['NJ'];
		}
		if( !empty($_POST ['KMBH'])){
			$map['KC_KMBH'] = $_POST ['KMBH'];
		}
		if(!empty($_POST['KCMC'])) {
			$KCMC = $_POST['KCMC'];
			$map['KC_BJMC'] = array('like',"%". $KCMC ."%");
		}
		
		$Course = M ("Course");
		$total = $Course->where($map)->count (); // 计算总数
	
		$courseList = array ();
		$courseList = $Course->where($map)->limit ( ($pagenum - 1) * $rowsnum . ',' . $rowsnum )->order ( 'id asc' )->select ();
		$resultJson = json_encode($courseList);
		if($resultJson == "null"){//如果查询结果返回为null
			$resultJson = "[]";
		}
		$json = '{"total":' . $total . ',"rows":' . $resultJson . '}'; // 重要，easyui的标准数据格式，数据总数和数据内容在同一个json中
		echo $json;
	}
	
	public function studentList() {
		
		$kcid = null;
		if(!empty($_POST['KCID'])) {
			$kcid = $_POST['KCID'];
		}
		
		
		if(empty($kcid)){
			$resultJson = "[]";
			$json = '{"total":' . $total . ',"rows":' . $resultJson . '}';
			echo $json;
			return;
		}
		
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;

		$offset = ($page-1)*$rows;
		$student = D ( "Student" );
		$result = $student->getCourseStudentList($kcid,$offset,$rows);
		echo json_encode($result);
	}
}
?>
